﻿<%@ WebHandler Language="C#" Class="AjaxSubmitFlag" %>

using System;
using System.Web;
using System.Data;

public class AjaxSubmitFlag : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        string strFlowName = context.Server.UrlDecode(context.Request["dataFlowname"]);
        string strFlowType = context.Server.UrlDecode(context.Request["flowType"]);
        string strUserID = context.Request["userId"];
        string strUserName = context.Request["userName"];
        string strBgFlag = context.Request["bgflag"];
        string strYqFlag = context.Request["yqflag"];
        string strIID = context.Request["dataIId"];

        //先处理iid的问题
        ChBusiness.Wsbs.ShenBaoSubmit submit = new ChBusiness.Wsbs.ShenBaoSubmit();
        int nReturnSubmit = submit.InsertSubmitInfo(strIID, strFlowName, strUserID);
        
        if (strBgFlag == "3" || strYqFlag == "3")//在办事项的变更或延期操作
        {
            WF_DataAccess.IDataAccess ida = WF_Business.SysParams.OAConnection();
            ExtBusiness.FlowOperation.RequestFlowOperation rfoTemp = new ExtBusiness.FlowOperation.RequestFlowOperation();

            if (strBgFlag == "3")//在办事项的变更操作
            {
                rfoTemp.UpdateFieldValue("4", "is_bg", strIID, ref ida);
            }
            else if (strYqFlag == "3")//在办事项的延期操作
            {
                rfoTemp.UpdateFieldValue("4", "is_yq", strIID, ref ida);
            } 

            //取消挂起
            ExtBusiness.FlowOperation.HandleCaseService hcsTemp = new ExtBusiness.FlowOperation.HandleCaseService();
            hcsTemp.CancelSuspend(strUserID, strIID);
            context.Response.Write("提交成功");
        }
        else
        {
            context.Response.Write(PostIId(strIID, strFlowName, strUserID, strUserName, strBgFlag,strFlowType));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// 提交并设置状态位
    /// </summary>
    /// <param name="strIId"></param>
    /// <param name="strFlowname">办理事项名称</param>
    /// <param name="strUserID"></param>
    /// <param name="strUserName"></param>
    /// <param name="strBgFlag">变更标志</param>
    /// <param name="strFlowType">办理事项分类</param>
    /// <returns></returns>
    public string PostIId(string strIId, string strFlowname, string strUserID, string strUserName, string strBgFlag, string strFlowType)
    {
        ChBusiness.Wsbs.ShenBaoSubmit submit = new ChBusiness.Wsbs.ShenBaoSubmit();
        string strFlag = submit.GetFlag(strFlowname);
        if (strFlag == "1")//判断是否所有附件均以上传
        {
            ChBusiness.Common.UploadFileClass upload = new ChBusiness.Common.UploadFileClass();

            string strAlredyCount = upload.GetAlreadyUpdateCount(strIId, strFlowname);
            string strCount = upload.GetUpdateCount(strFlowname);
            if (strAlredyCount != strCount)
            {
                return "";
            }
        }

        int nReturn = 0;
        nReturn = submit.UpdateSubmit(strIId, 1);

        //添加操作日志
        //string strSql = string.Format(@"update XT_SUBMIT_INFO set SUBMITFLAG={1}, edittime=sysdate where IID='{0}'", strIId, 1);
        //string strRemark = string.Format("提交{0}的业务,申请编号为: {1}", strFlowType, strIId);
        //ChBusiness.Common.SystemLogs.AddSystemLogs(strUserID, "update", strRemark, strSql);

        if (nReturn == 1)
        {
            //提交成功后发送消息
            //ChBusiness.Wsbs.Messagebox message = new ChBusiness.Wsbs.Messagebox();
            //DataTable dtTemp = message.GetRequestSet(0, "已经提交");
            //string strMsgContent = string.Empty;
            //string strStepNo = string.Empty;

            //if (dtTemp.Rows.Count > 0)
            //{
            //    strStepNo = dtTemp.Rows[0]["step_no"].ToString();
            //    strMsgContent = dtTemp.Rows[0]["step_msg"].ToString();
            //}
            //if (!string.IsNullOrEmpty(strMsgContent))//当消息内容设置为空时，将不再发送消息。
            //{
            //    try
            //    {
            //        strMsgContent = string.Format(strMsgContent, strUserName, strFlowType);
            //    }
            //    catch { }

            //    message.InsertMeaasge(strMsgContent, "", strUserName, strUserID);
            //}
            //message.UpdateUserStepNO(strUserID, strStepNo);

            return "提交成功";
        }

        return "";
    }
}